<?
	$params[sid] = $sid;
	$params[action] = "changeDetails";
	if (isset($from_page)) {
               $params['from_page'] = $from_page;
        }
	$url = "$baseURL/$webDIR/?".encode_params($params);

	$info1 = list_details($id,'array');
	$info1 = $info1[0];
	$info = array_merge($info1,$info2);

	//	nd4wd patch select the reseller details from rp2

	$query = "SELECT reseller_id as id,name as reseller,password,first_name as firstname,last_name as lastname,company,email,phone,address1,address2,city,state,zip,country,tax_id,newsletter,company as company_name,vat_num,vat_registered FROM resellers WHERE reseller_id='$id'";
	$GLOBALS[master_db]->query($query);
	$info = $GLOBALS[master_db]->getNext();
	$info[newsletter] = ($info[newsletter] == 't' ? 'yes' : 'no');
	$info[vat_registered] = ($info[vat_registered] == 't' ? 1 : 0);

	//	nd4wd patch select the reseller details from rp2
?>
<script>
function showVAT(selectBoxVAT) {
	if (typeof(selectBoxVAT) == 'string') {
		var vatSelect = document.getElementById(selectBoxVAT);
		var optionSelect = document.getElementById(vatSelect.value);

		if (optionSelect.labela == 1) {
			showHide (true, 'vat_radio');
      showHide (true, 'vat_text');
		}
    else {
    	showHide (false, 'vat_radio');
      showHide (false, 'vat_text');
    }
	}
}

function showVatNum(show) {
  showHide (show, 'vat_input');
	showHide (show, 'vat_input1');
}

function showHide (show, objectId) {
	if (typeof(objectId) == 'string') {
		var Box = document.getElementById(objectId);

		switch (show) {
			case true:
				Box.style.display = 'block';
				break;
			case false:
				Box.style.display = 'none';
				break;
    }
	}
}

/*
function makeCurrentBold() {
	var RadioButton = document.getElementByName('plan');
  alert(RadioButton);
  if (typeof(RadioButton) == 'object') {
  	var planId = RadioButton.value;

    makeBold('plan_name_'+planId);
    makeBold('plan_features_'+planId);
  }
}
*/

function makeBold(objectId) {
	if (typeof(objectId) == 'string') {
		var ObjectBold = document.getElementById(objectId);

    ObjectBold.innerHTML = '<b>'+ObjectBold.innerHTML+'</b>';
  }
}

function checkCompany(companyId) {
  if (typeof(companyId) == 'string') {
    var CompanyObject = eval('document.orderForm.'+companyId);

    if (CompanyObject.value == '') {
    	alert('Please fill in the \'Company Name\' field first!');
      CompanyObject.focus();
    }
  }
}

function MM_preloadImages() { //v3.0
  var d = document;
  if(d.images) {
  	if(!d.MM_p) {
    	d.MM_p = new Array();
    }

    var i , j = d.MM_p.length, a = MM_preloadImages.arguments;

    for(i = 0; i < a.length; i++) {
      if (a[i].indexOf("#") != 0) {
      	d.MM_p[j] = new Image;
        d.MM_p[j++].src = a[i];
      }
    }
  }
}

// set/unset VAT if there isn't company name
function checkCompany(formObject) {
	if (typeof(formObject) == 'undefined') {
		return false;
	}

	if (formObject.company_name.value == '') {
		formObject.vat_registered[0].click();
	}
}
</script>
<!-- default Vat fields style -->
<style>
 #vat_input {
 	display: none;
 }
 #vat_input1 {
 	display: none;
 }
</style>
<!-- end: default Vat fields style -->
<?php
if (isset($from_page)) {
      $params[sid] = $sid;
      $params[action] = "home";
      $url2 = "$baseURL/$webDIR/?".encode_params($params);
      echo "<div style='padding: 4 4 4 4; text-align:right;'><a href='$url2'>&laquo; Back to Home</a><br></div>";
}
?>
<table width="550">
  <tr>
    <td colspan=2><font class="text"><b><?=translate('change_acc_det');?><br>
      <br>
      </b>
      <?=translate('change_acc_det_desc');?> </font></td>
  </tr>
</table>
<br>
<?
	if($errorMsg) {
		include ('errorMsg.html');
	}
	if($okMsg) {
		include ('okMsg.html');
	}
?>

<br />
<TABLE border=1 class='bTable' cellspacing='0' width="550">
  <form action='<?=$url;?>' method='POST' name="orderForm">
	<tr>
		<th colspan='2'>
			<?=translate('contact_info');?>
		</th>
	</tr>
	<tr <? if($errorCode==1) echo "class='err'"; ?>><td width='150'><?=translate('username');?>:</td>
		<td>
			<?=$info[reseller];?>
		</td>
	</tr>
	<tr <? if($errorCode==2) echo "class='err'"; ?>><td width='150'><?=translate('password');?>:</td>
		<td>
			<input type='password'  name='password' value='<?=$info[password_];?>'>
        <?=translate('pass_not_req');?> </td>
	</tr>
	<tr <? if($errorCode==2) echo "class='err'"; ?>><td width='150'><?=translate('re_password');?>:</td>
		<td>
			<input type='password' name='repassword' value='<?=$info[password_];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==3) echo "class='err'"; ?>><td width='150'><?=translate('1st_name');?>:</td>
		<td>
			<input type='text' name='firstname' value='<?=$info[firstname];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==4) echo "class='err'"; ?>><td width='150'><?=translate('last_name');?>:</td>
		<td>
			<input type='text' name='lastname' value='<?=$info[lastname];?>'>
		</td>
	</tr>
  <tr <? if($errorCode==14) echo "class='err'"; ?>><td width='150'>Company Name (optional):</td>
		<td>
      <input class='txt' type='text' maxlength='32' name='company_name' value='<?=$info[company_name];?>' onKeyUp='checkCompany(this.form);'>
		</td>
	</tr>
	<tr <? if($errorCode==5) echo "class='err'"; ?>><td width='150'><?=translate('email');?>:</td>
		<td>
			<input type='text' name='email' value='<?=$info[email];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==6) echo "class='err'"; ?>><td width='150'><?=translate('phone');?>:</td>
		<td>
			<input type='text' name='phone' value='<?=$info[phone];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==7) echo "class='err'"; ?>><td width='150'><?=translate('address1');?>:</td>
		<td>
			<input type='text' name='address1' value='<?=$info[address1];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==7) echo "class='err'"; ?>><td width='150'><?=translate('address2');?>:</td>
		<td>
			<input type='text' name='address2' value='<?=$info[address2];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==8) echo "class='err'"; ?>><td width='150'><?=translate('city');?>:</td>
		<td>
			<input type='text' name='city' value='<?=$info[city];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==9) echo "class='err'"; ?>><td width='150'><?=translate('state');?>:</td>
		<td>
			<input type='text' name='state' value='<?=$info[state];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==10) echo "class='err'"; ?>><td width='150'><?=translate('zip');?></td>
		<td>
			<input type='text' name='zip' value='<?=$info[zip];?>'>
		</td>
	</tr>
	<tr <? if($errorCode==11) echo "class='err'"; ?>><td width='150'><?=translate('country');?></td>
		<td>
			<select id='country' name='country' onChange="javascript: showVAT('country');">
				<? echo get_countries($info['country'], TRUE); ?>
			</select>
		</td>
	</tr>
  <tr <? if($errorCode==15) echo "class='err'"; ?>>
		<td width='150'><div id="vat_text">European Union Customers:</div></td>
    <td>
			<div id="vat_radio">
			<input class='txt' type='radio' name='vat_registered' value='0' checked onClick="javascript: showVatNum(false);"> I am not VAT registered<br>
			<input class='txt' type='radio' name='vat_registered' value='1' onClick="javascript: showVatNum(true);"> I am VAT registered
			</div>
		</td>
	</tr>
	<tr <? if($errorCode==11) echo "class='err'"; ?>>
  	<td><div id="vat_input">VAT Number:</div></td>
    <td><div id="vat_input1"><input class='txt' type='text' maxlength='32' name='vat_num' value='<?=$info['vat_num']?>' onFocus="javascript: checkCompany('company_name');"></div></td>
  </tr>
	<tr <? if($errorCode==13) echo "class='err'"; ?>><td width='150'><?=translate('receive_news');?></td>
		<td>
			<input type='radio' name='newsletter' value='yes' <?if($info[newsletter]=='yes') echo 'checked'?>><?=translate('receive');?>
			<input type='radio' name='newsletter' value='no'  <?if($info[newsletter]=='no') echo 'checked'?>><?=translate('dont_receive');?>
		</td>
	</tr>
<!--
	<tr align="left" valign="middle">
		<td rowspan="2" >Enter the word as it is shown<br>in the box.</td>
		<td><font size="2"><img src='<?$params[sid]=$sid;$params[action]="5";	echo "$baseURL/signup/index.php?".encode_params($params); ?>'></font></td>
	</tr>
	<tr align="left" valign="middle">
		<td><span class="text"><font size="2"><input type=text name='verif' size=8></font></span></td>
	</tr>
-->
	<tr><td colspan='2' align='center'>
		<input type='button' value='<?=translate('back');?>' onClick='javascript:history.go(-1)'>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type='submit' value='<?=translate('change');?>'>
	</td></tr>
	</form>
</TABLE>
<script>
// Vat
showVAT ('country');

<?php
	if ($info['vat_registered'] == 1) {
		echo 'document.orderForm.vat_registered[1].click();';
  }
?>
// end: Vat
</script>
